package com.panopset.svg;

import java.awt.Image;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

import javax.swing.ImageIcon;

//import org.apache.batik.transcoder.TranscoderInput;
//import org.apache.batik.transcoder.TranscoderOutput;
//import org.apache.batik.transcoder.image.PNGTranscoder;

import com.panopset.compat.Strings;
import com.panopset.Util;

/**
 * Convert SVG to PNG using
 * <a href="http://xmlgraphics.apache.org/batik/">batik</a> API.
 *
 * @author Karl Dinwiddie
 *
 */
public class Svg2img {

    /**
     *
     * @param is .svg input stream.
     * @param width Width desired, height will be proportional.
     * @return PNG image from SVG data stream.
     */
    public static Image convert(final InputStream is, final float width) {
//        PNGTranscoder t = new PNGTranscoder();
//
//        Util.log("classpath: " + System.getProperty("java.class.path").replace(";", ";" + Strings.getEol()));
//
//
//        try {
//            TranscoderInput input = new TranscoderInput(is);
//            t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, width);
//            ByteArrayOutputStream bos = new ByteArrayOutputStream();
//            OutputStream ostream = new BufferedOutputStream(bos);
//            TranscoderOutput output = new TranscoderOutput(ostream);
//            t.transcode(input, output);
//            ostream.flush();
//            ostream.close();
//            return new ImageIcon(bos.toByteArray()).getImage();
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
        return null;
    }
}
